package edu.ciee.tz.action;

import java.util.List;

import javax.annotation.Resource;

import edu.ciee.tz.dao.LaiyuanDAO;
import edu.ciee.tz.model.Laiyuan;

public class LaiyuanAction {
	private int id;
	private String name;
	private String product_type;
	private String tele;
	
	private String tip;
	private List resultList;
	private LaiyuanDAO laiyuanDAO;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getProduct_type() {
		return product_type;
	}
	public void setProduct_type(String product_type) {
		this.product_type = product_type;
	}
	public String getTele() {
		return tele;
	}
	public void setTele(String tele) {
		this.tele = tele;
	}
	
	public String getTip() {
		return tip;
	}
	public void setTip(String tip) {
		this.tip = tip;
	}
	public List getResultList() {
		return resultList;
	}
	public void setResultList(List resultList) {
		this.resultList = resultList;
	}
	public LaiyuanDAO getLaiyuanDAO() {
		return laiyuanDAO;
	}
	@Resource
	public void setLaiyuanDAO(LaiyuanDAO laiyuanDAO) {
		this.laiyuanDAO = laiyuanDAO;
	}
	public String forLuru() throws Exception {		
		return "success";		
	}
	public String insert(){
		try{
			Laiyuan ly=new Laiyuan();
			ly.setName(this.getName());
			ly.setProduct_type(this.getProduct_type());
			ly.setTele(this.getTele());
			
			this.getLaiyuanDAO().insert(ly);
			return "success";
		}catch(Exception e){
			this.setTip(e.toString());
			return "error";
		}
	}
	public String delete(){
		try{
			Laiyuan ly=new Laiyuan();
			ly.setId(this.getId());
			ly.setName(this.getName());
			ly.setProduct_type(this.getProduct_type());
			ly.setTele(this.getTele());
			
			this.getLaiyuanDAO().delete(ly);
			return "refresh";
		}catch(Exception e){
			this.setTip(e.toString());
			return "error";
		}
	}
	public String forEdit(){
		return "success";
	}
	public String edit(){
		try{
			Laiyuan ly=new Laiyuan();
			ly.setId(this.getId());
			ly.setName(this.getName());
			ly.setProduct_type(this.getProduct_type());
			ly.setTele(this.getTele());
			
			this.getLaiyuanDAO().update(ly);
			return "refresh";
		}catch(Exception e){
			this.setTip(e.toString());
			return "error";
		}
	}
	public String search(){
		try{
			Laiyuan ly=new Laiyuan();
			ly.setId(this.getId());
			ly.setName(this.getName());
			ly.setProduct_type(this.getProduct_type());
			ly.setTele(this.getTele());
			
			this.setResultList(this.getLaiyuanDAO().search(ly));
			return "success";
		}catch(Exception e){
			this.setTip(e.toString());
			return "error";
		}
	}
}
